<template>
  <TableView
    ref="tableView"
    :table-attrs="{ api: fetchList }"
    form-path="/asset/fyassetpublicbarcode/publicbarcodeForm/{id:-1}"
    :search-model="searchForm"
    :toolbar-attrs="{
      buttons: [
        'slot',
        {
          del: permissions.publicbarcode_fyassetpublicbarcode_del,
          create: permissions.publicbarcode_fyassetpublicbarcode_add
        }
      ]
    }"
    :delete-api="batchDelete">
    >
    <template #toolbar-button>
      <ToolbarButton
        v-if="permissions.publicbarcode_fyassetpublicbarcode_export"
        type="primary"
        icon="el-icon-download"
        label="导出"
        @click="exportExcel()" />
    </template>
    <template #columns>
      <TableColumn label="条形码" prop="barcode" clickable />
      <TableColumn label="名称" prop="name" clickable />
      <TableColumn label="地址" prop="place" clickable />
      <TableColumn label="计量单位" prop="unit" clickable />
      <TableColumn label="规格型号" prop="standard" />
      <TableColumn label="价格" prop="price" />
      <TableColumn label="供应商" prop="supplier" />
      <TableColumn label="品牌" prop="brand" />
      <TableColumn label="国家" prop="country" />
    </template>
    <template #search-form>
      <FormInput v-model="searchForm.barcode" label="条形码" prop="barcode" />
      <FormInput v-model="searchForm.name" label="名称" prop="name" />
      <FormInput v-model="searchForm.price" label="地址" prop="price" />
      <FormInput v-model="searchForm.unit" label="计量单位" prop="unit" />
      <FormInput v-model="searchForm.standard" label="规格型号" prop="standard" />
      <FormInput v-model="searchForm.supplier" label="供应商" prop="supplier" />
    </template>
  </TableView>
</template>

<script>
  import { mapState } from 'vuex'
  import { services } from '@/config'
  import { fetchList, batchDelete } from '@/api/asset/fyassetpublicbarcode'

  export default {
    name: 'PublicbarcodeView',
    data() {
      return {
        searchForm: {
          barcode: '',
          name: '',
          price: '',
          unit: '',
          standard: '',
          supplier: ''
        }
      }
    },
    computed: {
      ...mapState('user', ['permissions'])
    },
    methods: {
      fetchList,
      batchDelete,
      //  导出excel
      exportExcel() {
        this.$downBlobFile(
          `${services.assetService}fyassetpublicbarcode/export`,
          this.searchForm,
          `条码库${this.$dateFormat(new Date())}.xlsx`
        )
      }
    }
  }
</script>
